# -*- coding: utf-8 -*-
import cv2
cap = cv2.VideoCapture("images/张琳晗.mp4")

flag = 0

if(cap.isOpened()): #视频打开成功
  flag = 1
else:
  flag = 0
  print ("read error!")

if(flag==1):
  while(True):
    ret,frame = cap.read()#读取一帧
    #if(frame is None):
    if ret==False: #读取帧失败
      break
    #gray_img = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)#转为灰度图
    gray_img = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)#转到HSV空间
    cv2.imshow("frame", gray_img)
    # imgPaht = "D:\\pics\\"+str(i)+".bmp" #---第一种格式化字符串的方法    
    # imgPaht = "E:\\pics\\%s.bmp"%str(i)#---第二种格式化字符串方法
    #cv2.imshow("video", frame)
    # cv2.imwrite(imgPaht,frame)
    if cv2.waitKey(50)&0xFF ==27: #按下Esc键退出
      cv2.imwrite("images/1.bmp",gray_img)
      break

cap.release()
cv2.destroyAllWindows()
      
